//
//  DsTouxiangView.m
//  Tour
//
//  Created by 张张烨 on 16/3/9.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "DsTouxiangView.h"

@interface DsTouxiangView ()
@property (nonatomic, strong)UIButton *xihuan;
@property (nonatomic, strong)UIButton *youji;
@end

@implementation DsTouxiangView

- (instancetype)initWithFrame:(CGRect)frame mingzi:(NSString *)mingzi touxiang:(NSString *)touxiang xingbie:(NSNumber*)xingbie
{
    self = [super initWithFrame:frame];
    if (self) {
        // 头像
        UIImageView *head = [[UIImageView alloc]initWithFrame:CGRectMake(10 * KUAN, 74 * GAO, 50 * KUAN, 50 * GAO)];
        [head sd_setImageWithURL:[NSURL URLWithString:touxiang]];
        head.layer.cornerRadius = 10;
        head.clipsToBounds = YES;
        [self addSubview:head];
        // 判断男女
        UIImageView *gender = [[UIImageView alloc]initWithFrame:CGRectMake(head.frame.size.width + head.frame.origin.x + 10 + 10, 84 * GAO, 20, 20)];
        [self addSubview:gender];
        NSNumber *genderstr = xingbie ;
        
        if ([genderstr integerValue] == 1) {
            gender.image = [UIImage imageNamed:@"male.png"];
        }else{
            gender.image = [UIImage imageNamed:@"female.png"];
        }
        //用户名
        UILabel *username = [[UILabel alloc]initWithFrame:CGRectMake(gender.frame.size.width + gender.frame.origin.x + 10, 84 * GAO, 200 * KUAN, 20 * GAO)];
        username.text = mingzi;
        username.font = [UIFont systemFontOfSize:15];
        [self addSubview:username];
  
        // 线
        UILabel *xian = [[UILabel alloc]initWithFrame:CGRectMake(0, head.frame.size.height + head.frame.origin.y + 20, WIDTH, 1)];
        xian.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:xian];
        
        // 游记 and 喜欢 按键
        // 游记btn
        self.youji = [UIButton buttonWithType:UIButtonTypeSystem];
        _youji.frame = CGRectMake(0, xian.frame.origin.y + xian.frame.size.height, WIDTH / 2, 30  * GAO);
        [_youji setTitle:@"游记" forState:UIControlStateNormal];
        [_youji setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [_youji addTarget:self action:@selector(travelbtn) forControlEvents:UIControlEventTouchUpInside];
        _youji.tintColor = [UIColor lightGrayColor];
        [self addSubview:_youji];
        // 喜欢btn
         self.xihuan = [UIButton buttonWithType:UIButtonTypeSystem];
        _xihuan.frame = CGRectMake(WIDTH / 2, xian.frame.origin.y + xian.frame.size.height, WIDTH / 2, 30 * GAO);
        [_xihuan setTitle:@"喜欢" forState:UIControlStateNormal];
        [_xihuan addTarget:self action:@selector(likebtn) forControlEvents:UIControlEventTouchUpInside];
        _xihuan.tintColor = [UIColor lightGrayColor];
        [self addSubview:_xihuan];
        
        // 分隔 游记 与 喜欢的竖线
        UILabel *shuxian = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH / 2, xian.frame.origin.y + xian.frame.size.height + 5, 1, 20)];
        shuxian.text = @"丨";
        shuxian.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:shuxian];
      
        
        // 线
        UILabel *fengexian = [[UILabel alloc]initWithFrame:CGRectMake(0, _xihuan.frame.size.height + _xihuan.frame.origin.y, WIDTH, 1)];
        fengexian.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:fengexian];    }
   
    return self;
}

-(void)travelbtn{
    [_youji setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [_xihuan setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    
    [self.delegate youji];
    
}
/**<  喜欢 */
- (void)likebtn{
    
    [_youji setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [_xihuan setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    
    [self.delegate xihuan];
}

@end
